<?php
/***********************************************************
	Filename: phpok.sys.php
	Note	: 参数调用涉及到的函数
	Version : 3.0
	Author  : qinggan
	Update  : 2010-01-07
***********************************************************/
if(!function_exists("phpok"))
{
	//标识串
	//vartext，数组，将合并到后台的参数调用中
	//格式如：array("id"=>1) 这样子的形式 或 cs=1,cid=1这样子
	function phpok($var,$vartext="")
	{
		if(!$var)
		{
			return false;
		}
		$app = sys_init();
		$app->load_lib("phpok");
		$app->phpok_lib->langid($_SESSION["sys_lang_id"]);
		$app->load_model("phpok");
		$app->phpok_m->langid($_SESSION["sys_lang_id"]);
		$rs = $app->phpok_m->get_one_sign($var);
		$in_var = array();
		if($rs["vartext"])
		{
			$varlist = explode(",",$rs["vartext"]);
			foreach($varlist AS $key=>$value)
			{
				$in_var[$value] = $app->trans_lib->safe($value);
			}
		}
		$app->phpok_lib->set_rs($rs);
		$app->phpok_lib->thumbtype($rs["inpic"]);//指定小图类型
		//获取所有字段信息
		if($rs["mid"])
		{
			$mid = $rs["mid"];
			$in_var["mid"] = $rs["mid"];
		}
		if($rs["cid"])
		{
			$cid = $rs["cid"];
			$in_var["cid"] = $rs["cid"];
		}
		//如果系统有设置主题标签
		if($rs["extsign"] && $rs["maxcount"] == 1)
		{
			$in_var["ts"] = $rs["extsign"];
		}
		//合并传过来的数组
		if($vartext)
		{
			if(is_array($vartext) && count($vartext)>0)
			{
				$in_var = array_merge($in_var,$vartext);
			}
			else
			{
				$varlist = explode("&",$vartext);
				$v_list = array();
				foreach($varlist AS $key=>$value)
				{
					$v = explode("=",$value);
					$v_list[$v[0]] = $v[1];
				}
				$in_var = array_merge($in_var,$v_list);
			}
		}
		//执行内容信息
		if($rs["intype"] == "sql")
		{
			if(!$rs["typetext"])
			{
				return false;
			}
			$get_type = $rs["maxcount"] == 1 ? "get_one" : "get_all";
			$sql = sys_eval($rs["typetext"],$in_var);//参数替换值
			return $app->phpok_lib->exec_sql($sql,$get_type);
		}
		elseif($rs["intype"] == "sign")
		{
			if($rs["datatype"] == "cate")
			{
				$rslist = $app->phpok_lib->cate_sql($in_var);
			}
			else
			{
				$rslist = $app->phpok_lib->list_sql($in_var,$rs["maxcount"],$rs["orderby"]);
			}
			return $rslist;
		}
		else
		{
			if(!$rs["typetext"])
			{
				return false;
			}
			$content = sys_eval($rs["typetext"],$in_var);
			//$rs["content"] = $content;
			return array("title"=>$rs["title"],"content"=>$content);
		}
	}
}

//上下主题
if(!function_exists("phpok_next_prev"))
{
	//id:主题ID
	//cateid：主题所属分类ID，如果分类ID为0，将读取模块ID信息
	//pictype：关联的图片类型，不关联为空
	//num：读取数量
	function phpok_next_prev($id,$cateid=0,$pictype="",$num=1)
	{
		$app = sys_init();
		$app->load_model("np_model",true);
		$app->np_model->langid($_SESSION["sys_lang_id"]);
		$rs = array();
		$next_list = $app->np_model->get_next($id,$cateid,$pictype,$num);
		if($next_list)
		{
			$rs["next"] = $next_list;
		}
		$prev_list = $app->np_model->get_prev($id,$cateid,$pictype,$num);
		if($prev_list)
		{
			$rs["prev"] = $prev_list;
		}
		if($rs["next"] || $rs["prev"])
		{
			return $rs;
		}
		else
		{
			return false;
		}
	}
}

//读取语言包
if(!function_exists("phpok_lang"))
{
	function phpok_lang()
	{
		$app = sys_init();
		return $app->langconfig_m->get_all();
	}
}

//读取导航菜单
if(!function_exists("phpok_menu"))
{
	function phpok_menu($highlight="")
	{
		$app = sys_init();
		$app->load_model("menu");
		$rslist = $app->menu_m->get_all($highlight);
		if(!$rslist)
		{
			return false;
		}
		return $rslist;
	}
}

?>